package com.opages.transaction.message.model;

import io.swagger.annotations.ApiModelProperty;

import java.util.Date;
import java.util.UUID;

/**
 * 事务消息
 * @author daizhong.liu
 * @create 2021-11-01 14:39
 **/
public class TransactionMessage {
    /**
     * 唯一主键
     */
    @ApiModelProperty(value="id")
    private Long id;
    /** 删除标志：0未删除，1己删除 */
    @ApiModelProperty(value="deleteFlag")
    private String deleteFlag;
    /** 创建时间 */
    @ApiModelProperty(value="insertDatetime")
    private Date insertDatetime;
    /** 创建者 */
    @ApiModelProperty(value="insertUserName")
    private String insertUserName;
    /** 更新时间 */
    @ApiModelProperty(value="updateDatetime")
    private Date updateDatetime;
    /** 更新者 */
    @ApiModelProperty(value="updateUserName")
    private String updateUserName;
    /** UUID */
    @ApiModelProperty(value="uuid")
    private String uuid;
    /** 消息内容 */
    @ApiModelProperty(value="消息内容")
    private String messageBody;
    /** 消费队列 */
    @ApiModelProperty(value="消费队列")
    private String consumerQueue;
    /** 消息重发次数 */
    @ApiModelProperty(value="消息重发次数")
    private Integer messageSendTimes;
    /** 是否死亡 */
    @ApiModelProperty(value="是否死亡(1是，0否)")
    private String areadlyDead;
    /** 状态（待确认,发送中） */
    @ApiModelProperty(value="状态(1待确认,2发送中)")
    private String status;
    /** 消息确认url */
    @ApiModelProperty(value="消息确认url")
    private String msgConfirmUrl;
    /** 备注 */
    @ApiModelProperty(value="备注")
    private String remark;
    /** 扩展字段 */
    @ApiModelProperty(value="扩展字段")
    private String field1;
    /** 扩展字段 */
    @ApiModelProperty(value="扩展字段")
    private String field2;
    /** 扩展字段 */
    @ApiModelProperty(value="扩展字段")
    private String field3;
    /**
     * 扩展字段：创建时间之前，用于查询比创建时间靠前的待确认消息的查询条件
     */
    private String createTimeBefore;

    public TransactionMessage() {

    }
    public TransactionMessage(String uuid,String consumerQueue,String msgBody,String msgConfirmUrl) {
        this.uuid = uuid;
        this.consumerQueue = consumerQueue;
        this.messageBody = msgBody;
        this.msgConfirmUrl = msgConfirmUrl;
    }
    public void initBaseData() {
        if (id == null){
            this.setInsertDatetime(new Date());
            this.setUpdateDatetime(new Date());
            //防止controller预先生成uuid作为唯一键时，不在初始化中生成
            if(this.getUuid()==null||"".equals(this.getUuid())) {
                this.setUuid(UUID.randomUUID().toString());
            }
            this.setDeleteFlag(BaseConstant.SYS_DELETE_FLAG_0);
        }else{
            this.setUpdateDatetime(new Date());
        }
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(String deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public Date getInsertDatetime() {
        return insertDatetime;
    }

    public void setInsertDatetime(Date insertDatetime) {
        this.insertDatetime = insertDatetime;
    }

    public String getInsertUserName() {
        return insertUserName;
    }

    public void setInsertUserName(String insertUserName) {
        this.insertUserName = insertUserName;
    }

    public Date getUpdateDatetime() {
        return updateDatetime;
    }

    public void setUpdateDatetime(Date updateDatetime) {
        this.updateDatetime = updateDatetime;
    }

    public String getUpdateUserName() {
        return updateUserName;
    }

    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getMessageBody() {
        return messageBody;
    }

    public void setMessageBody(String messageBody) {
        this.messageBody = messageBody;
    }

    public String getConsumerQueue() {
        return consumerQueue;
    }

    public void setConsumerQueue(String consumerQueue) {
        this.consumerQueue = consumerQueue;
    }

    public Integer getMessageSendTimes() {
        return messageSendTimes;
    }

    public void setMessageSendTimes(Integer messageSendTimes) {
        this.messageSendTimes = messageSendTimes;
    }

    public String getAreadlyDead() {
        return areadlyDead;
    }

    public void setAreadlyDead(String areadlyDead) {
        this.areadlyDead = areadlyDead;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsgConfirmUrl() {
        return msgConfirmUrl;
    }

    public void setMsgConfirmUrl(String msgConfirmUrl) {
        this.msgConfirmUrl = msgConfirmUrl;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getField1() {
        return field1;
    }

    public void setField1(String field1) {
        this.field1 = field1;
    }

    public String getField2() {
        return field2;
    }

    public void setField2(String field2) {
        this.field2 = field2;
    }

    public String getField3() {
        return field3;
    }

    public void setField3(String field3) {
        this.field3 = field3;
    }

    public String getCreateTimeBefore() {
        return createTimeBefore;
    }

    public void setCreateTimeBefore(String createTimeBefore) {
        this.createTimeBefore = createTimeBefore;
    }

    public void addSendTimes() {
        messageSendTimes++;
    }
}
